<?php

/**
 * WeEngine Api System
 *
 * (c) We7Team 2019 <https://www.w7.cc>
 *
 * This is not a free software
 * Using it under the license terms
 * visited https://www.w7.cc for more details
 */

namespace W7\Sdk\VSCode\Tests;

use W7\Sdk\VSCode\Traits\StorageTrait;

/**
 * fs read dir
 */
class TestDirectoryRead extends TestCase {
	use StorageTrait;

	/**
	 * @var string
	 */
	private $content = 'hello123456';
	/**
	 * @var string
	 */
	private $dirOne = '/api/readdir';
	/**
	 * @var string
	 */
	private $dirTwo = '';

	private $txtA = '';
	/**
	 * @var string
	 */
	private $route = '';

	protected function setUp(): void {
		parent::setUp(); // TODO: Change the autogenerated stub
		$this->route = route('vs.code.read.directory', ['uri' => $this->dirOne]);
		$this->dirTwo = $this->dirOne.'/a';
		$this->txtA = $this->dirOne.'/a.txt';
	}

	/**
	 * test read directory
	 */
	public function testReadDirectory() {
		$this->storageDeleteDir($this->dirOne);
		$this->storageDeleteDir($this->dirTwo);
		$this->storageDeleteFile($this->txtA);

		$this->storageMakeDir($this->dirOne);
		$this->assertTrue($this->storageIsExists($this->dirOne));

		$this->storageMakeDir($this->dirTwo);
		$this->assertTrue($this->storageIsExists($this->dirTwo));

		$this->storagePutContent($this->txtA, $this->content);
		$this->assertTrue($this->storageIsExists($this->txtA));

		$response = $this->getJson($this->route)->assertOk();
		$response->dump()->assertJsonCount(2);
	}
}
